package com.bwsoft.admin.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import com.bwsoft.admin.domain.Account;
import com.bwsoft.admin.domain.Advertisement;
import com.bwsoft.admin.domain.QualityControlJoiner;
import com.bwsoft.admin.domain.valueObject.AccountVO;
import com.bwsoft.model.Message;

public class ComAndLadAction extends BaseAction_ybd{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2898461392067671989L;
	
	String s_accountId;
	String s_compName;
	String s_account;
	String s_attestStatus;
	String s_jinyongFlag;
	String s_accountType;

	String cnasFlag;
	public int inspectors;
	
	public String comAndLadIndex(){
		return "comAndLadIndex";
	}
	
	/**
	 * 查询获取列表
	 */
	public String getComAndLadJson() {

		List<Account> comAndLadSet=null;
			//通过字典编号查询字典详情的分页集合
		comAndLadSet = comAndLadService.findData(page, rows, s_accountId,  s_compName,  s_account,  s_attestStatus,  s_jinyongFlag,  s_accountType);
			//通过编号查询字典集合的大小	
		Long count = comAndLadService.getTotalCount(s_accountId,  s_compName,  s_account,  s_attestStatus,  s_jinyongFlag,  s_accountType);
		
		List<AccountVO> listVo = comAndLadService.getVo(comAndLadSet);
		
		responseJson.put("total", count);
		responseJson.put("rows", listVo);

		return "mapJsonResult";
	}
	
	
	/**
	 * 保存或新增
	 * @return
	 */
	public String saveOrUpdateInfo(){
//		if(cl.getAccountId() == null || "".equals(cl.getAccountId())){
//			if(clImg1 == null || "".equals(clImg1)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "请上传认证图！");
//				return "mapJsonResult";
//			}
//			if(clImg1 != null && !"".equals(clImg1) && !newsService.isImage(clImg1ContentType)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "上传的文件不是图片类型！");
//				return "mapJsonResult";
//			}
//			if(clImg1 != null && !"".equals(clImg1) && !newsService.isFitSize(clImg1)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "图片不能超过8M！");
//				return "mapJsonResult";
//			}
//		}
		msg = comAndLadService.saveOrUpdateInfo(cl, clImg1, clImg1FileName, clImg2, clImg2FileName, cnasFlag);
		
//		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
//		responseJson.put("message", msg.getMsgStr());
//		return "mapJsonResult";
		response.setContentType("text/html;charset=utf-8");
		JSONObject json = new JSONObject();
		json.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		json.put("message", msg.getMsgStr());
		try {
			PrintWriter out = response.getWriter();
			out.write(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	/**
	 * 保存或新增
	 * @return
	 */
	public String saveOrUpdatePass(){
		msg = comAndLadService.saveOrUpdatePass(cl);
		
//		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
//		responseJson.put("message", msg.getMsgStr());
//		return "mapJsonResult";
		response.setContentType("text/html;charset=utf-8");
		JSONObject json = new JSONObject();
		json.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		json.put("message", msg.getMsgStr());
		try {
			PrintWriter out = response.getWriter();
			out.write(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	/**
	 * 获取详情内容
	 * @return
	 */
	public String comAndLadModifyInfo(){
		cl = comAndLadService.comAndLadModifyInfo(cl.getAccountId());
		
		List<Account> list = new ArrayList<Account>();
		list.add(cl);
		List<AccountVO> listVo = comAndLadService.getVo(list);
		
		responseJson.put("cl", listVo.get(0));
		return "mapJsonResult";
	}
	
	public String certified() {
		msg = comAndLadService.certified(cl.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}

	public String NonCertified() {
		msg = comAndLadService.NonCertified(cl.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}

	public String operation() {
		msg = comAndLadService.operation(cl.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}

	public String forbid() {
		msg = comAndLadService.forbid(cl.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}
	
	
	/**
	 * 质检人员查询获取列表
	 */
	public String showInspectors() {

		int count = 0;
		List<Account> inspectorsSet=null;
		
			
			//通过质量控制编号参加人详情的分页集合
		inspectorsSet = comAndLadService.findInspectorsData(page, rows, inspectors);
			//通过编号查询参加人集合的大小	
			count = comAndLadService.findInspectorsData(inspectors);
		
			List<AccountVO> listVo = comAndLadService.getVo(inspectorsSet);
			
		responseJson.put("total", count);
		responseJson.put("rows", listVo);

		return "mapJsonResult";
	}
	
//	-----------------------------------------------------------------------------------

	public String getS_accountId() {
		return s_accountId;
	}

	public void setS_accountId(String s_accountId) {
		this.s_accountId = s_accountId;
	}

	public String getS_compName() {
		return s_compName;
	}

	public void setS_compName(String s_compName) {
		this.s_compName = s_compName;
	}

	public String getS_account() {
		return s_account;
	}

	public void setS_account(String s_account) {
		this.s_account = s_account;
	}

	public String getS_attestStatus() {
		return s_attestStatus;
	}

	public void setS_attestStatus(String s_attestStatus) {
		this.s_attestStatus = s_attestStatus;
	}

	public String getS_jinyongFlag() {
		return s_jinyongFlag;
	}

	public void setS_jinyongFlag(String s_jinyongFlag) {
		this.s_jinyongFlag = s_jinyongFlag;
	}

	public String getS_accountType() {
		return s_accountType;
	}

	public void setS_accountType(String s_accountType) {
		this.s_accountType = s_accountType;
	}

	public String getCnasFlag() {
		return cnasFlag;
	}

	public void setCnasFlag(String cnasFlag) {
		this.cnasFlag = cnasFlag;
	}

	public int getInspectors() {
		return inspectors;
	}

	public void setInspectors(int inspectors) {
		this.inspectors = inspectors;
	}
	
}
